package com.fjb.service.product.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.mapper.product.ProductCategoryMapper;
import com.fjb.pojo.brand.BrandInfo;
import com.fjb.pojo.product.ProductCategory;
import com.fjb.pojo.product.query.ProductCategoryQuery;
import com.fjb.service.product.ProductCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * <p>
 * 产品分类 服务实现类
 * </p>
 *
 * @author hemiao
 * @since 2019-12-22
 */
@Service
public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMapper, ProductCategory> implements ProductCategoryService {
	
	@Autowired
	private ProductCategoryMapper productCategoryMapper;
	
	@Override
	public JsonTotalResult<List<ProductCategory>> selectPageList(ProductCategoryQuery categoryQuery,
			PageQuery pageQuery) {
		PageHelper.startPage(pageQuery.getCurrentPage(), pageQuery.getPageSize());
		QueryWrapper<ProductCategory> queryWrapper = new QueryWrapper<ProductCategory>();
		Integer id = categoryQuery.getId();
		if(id!=null) {	
			queryWrapper.eq("id", id).or().like("parent_ids", id+"%");
		}
		Integer brandId = categoryQuery.getBrandId();
		if(brandId!=null) {	
			queryWrapper.eq("brand_id", brandId);
		}
		List<ProductCategory> infoList = productCategoryMapper.selectList(queryWrapper);
		PageInfo<ProductCategory> pageInfo = new PageInfo<ProductCategory>(infoList);
		return new JsonTotalResult<List<ProductCategory>>(infoList, HttpCode.SUCCESS, pageInfo.getTotal());
	}

}
